<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class comment_controller extends CI_Controller {
	
	function __construct()
    {
		parent::__construct();
		$this->load->model('comment_model');
    }
	
	public function index()
	{
		exit;
	}
	
	
	public function ajax_get_article_comments()
	{
		$request_data = json_decode($_POST['request_data']);
		$response->article_comments = $this->comment_model->get_article_comments($request_data->article_id)->result();		
		$response->status = 200; 
		echo json_encode($response);
	}
	
	public function ajax_add_comment()
	{
		$request_data = json_decode($_POST['request_data']);
		
		// add article comment
		$article_comment['article_id'] =  $request_data->article_id;
		// $article_comment['comment_by_user_id'] =  $request_data->comment_by_user_id;
		$article_comment['comment_by_user_name'] =  $request_data->comment_by_user_name;
		$article_comment['comment_by_user_email'] =  $request_data->comment_by_user_email;
		$article_comment['comment'] =  $request_data->comment;
		$article_comment['comment_date'] =  date('Y-m-d H:m:s');
		
		$response->result = $this->comment_model->add_article_comments($article_comment);
		$response->status = ($response->result == TRUE ? 200 : 500);
		echo json_encode($response);
	}
}

/* End of file comment_controller.php */
/* Location: ./application/controllers/comment_controller.php */